package javacommon.base;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.dao.DataAccessException;



/**
 * @author badqiu
 */
public abstract class BaseManager<E, PK extends Serializable> {

	protected Log log = LogFactory.getLog(getClass());

	@SuppressWarnings("rawtypes")
	protected abstract EntityDao getEntityDao();

	@SuppressWarnings("unchecked")
	public E getById(PK id) throws DataAccessException {
		return (E) getEntityDao().getById(id);
	}

	@SuppressWarnings("unchecked")
	public List<E> findAll() throws DataAccessException {
		return getEntityDao().findAll();
	}

	
	@SuppressWarnings("unchecked")
	public void saveOrUpdate(E entity) throws DataAccessException {
		getEntityDao().saveOrUpdate(entity);
	}
	@SuppressWarnings("unchecked")
	public void save(E entity) throws DataAccessException {
		getEntityDao().save(entity);
	}
	@SuppressWarnings("unchecked")
	public void save(E entity,String errorTitle) throws DataAccessException {
		try{
			getEntityDao().save(entity);
		}catch(Exception e){
		}
	}
	@SuppressWarnings("unchecked")
	public void removeById(PK id) throws DataAccessException {
		getEntityDao().deleteById(id);
	}
	@SuppressWarnings("unchecked")
	public void update(E entity) throws DataAccessException {
		getEntityDao().update(entity);
	}
	
	@SuppressWarnings("unchecked")
	public boolean isUnique(E entity, String uniquePropertyNames)
			throws DataAccessException {
		return getEntityDao().isUnique(entity, uniquePropertyNames);
	}
}